// 信息提示
class clewInfo extends eui.Component{
    private clewKuang:eui.Group;
    private alphaBg:eui.Image;
    private btnYes:eui.Image;
    private btnNo:eui.Image;
    private btn1:eui.Group;
    private btn2:eui.Group;
    private tx:eui.Label;
    public OUTPUT_RESULT:string = "outputResult";
    private yesFun:Function;
    private noFun:Function;

    public constructor(){
        super();
        this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "src/Game/gameRoom/window/clewInfoSkin.exml";
    }
    private onComplete(){
        this.alphaBg.touchEnabled = true;
        this.once(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
        this.btnYes.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onYes,this);
        this.btnNo.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onNo,this);
        StageData.MainObj.addEventListener(Events.STAGE_SIZE,this.updateSize,this);
    }
    private onRemove(){
        this.btnYes.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onYes,this);
        this.btnNo.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onNo,this);
        StageData.MainObj.removeEventListener(Events.STAGE_SIZE,this.updateSize,this);
    }

    private onYes(){
        StageData.soundObj.soundSinglePlay("click");
        this.dispatchEventWith(this.OUTPUT_RESULT,false,true);
        if(this.yesFun){
            this.yesFun();
        }
    }
    private onNo(){
        StageData.soundObj.soundSinglePlay("click");
        this.dispatchEventWith(this.OUTPUT_RESULT,false,false);
        if(this.noFun){
            this.noFun();
        }
    }
    private updateSize(){
        this.alphaBg.width = StageData.W;
        this.alphaBg.height = StageData.H;
        this.clewKuang.x = (StageData.W - 573) / 2;
        this.clewKuang.y = (StageData.H - 333) / 2;
    }

    public clew(str:string,yesReturn:Function=null,noReturn:Function=null){
        StageData.soundObj.soundSinglePlay("down");
        this.yesFun = yesReturn;
        this.noFun = noReturn;
        if(this.yesFun&&this.noFun){
            this.btn1.x = 298;
            this.btn2.x = 60;
            this.btn2.visible = true;
            this.btn1.visible = true;
        }else if(!this.yesFun&&!this.noFun){
            this.btn1.x = 185;
            this.btn2.visible = false;
        }else if(this.yesFun&&!this.noFun){
            this.btn1.x = 185;
            this.btn2.visible = false;
        }
        this.tx.text = str;        
        this.updateSize();
    }
}